//引入代码
var call = require('../../util/request.js');
Page({
  data: {
    num:1,     //初始数量
  },
  
  onShow: function() {
  	
 },
  onReady: function() {
  
  
  },
  
  onLoad: function(options) {
  	//订单详细
  	call.getData('api/orderDetail?order_id=' + options.order_id, this.orderDetail, this.fail);
  	
  	
  	},
	orderDetail:function(data){
		this.setData({
			orders: data.data
		})
	},
	
	//加数量
	  bindPlus:function(item){
		var num =  item.currentTarget.dataset.num;
		
		 this.setData({
		  		num:num,
		})
		
		
		 
		if(num>=this.data.orders.valid_num){
			
			tt.showToast({
			  title: '亲,不能再加了',
			});
			
		}else{
			var num =  item.currentTarget.dataset.num;
			 num++;
			 
			 this.setData({
			  		num:num,
			})
			
		}
		
	  },
	  
	//减数量
	bindMinus:function(item){
		var num = item.currentTarget.dataset.num;
		if(num==1){
			tt.showToast({
			  title: '亲,不能再减了',
			});
		}else{
			num--;
			console.log('真实数量'+num)
			
			this.setData({
				  num:num,
				  /* total:this.data.calendarMoney*num */
			 })
		}
		
	},
	
	//申请退款
	refunds:function(e){
		   console.log('这是个直'+e.currentTarget.dataset.id)
		   var postData = {
			  order_id:e.currentTarget.dataset.id,
			  order_num:this.data.num
		   }
		   call.request('api/orderRefund',postData,this.orderRefund, this.fail);
	},
	
	orderRefund:function(data){
		//退款成功申请
		
		if(data.code==10000){
			tt.showToast({
			  title: '申请退款成功',
			});
			 tt.switchTab({ url: '/pages/personal/personal' })
		}
		
	},
	
	
});